package content.views;

import js.Dom.HtmlDom;
import js.Lib;
import tools.ASprite;
import tools.BoundProvider;
/**
 * basics
 * @author PRASS
 */

class BaseView extends ASprite
{

	public var view 		: HtmlDom;
	public var container 	: JQuery;
	public var id 			: String;
	public var rootID		: String;
	public var tpl			: String;
	public var html			: String;
	
	public function new( _id : String, _tpl : String = "" ) 
	{
		view = Lib.document.getElementById(_id);
		dom = new JQuery("#" + _id);
		rootID = _id;
			
		super(dom, _id);
		
		id = "container_" + _id;
		tpl = _tpl;
	
		dom.append('<div id="'+id+'"></div>');
		container = new JQuery("#" + id);
		container.css("background-image", "url(img/elements/u_mad_bro.gif)");
				
		removeChild();
		
		if ( _tpl == "" )
		{
			build();
			return;
		}
		
		container.load(tpl, _onLoaded);
		
	}
	
	private function _onLoaded( response : String, status : String, xhr ) : Void
	{
		if (status == 'error') {
			Lib.alert('ERROR');
		} else {
			html = response;
			build();
		}
	}
	
	public function build() : Void
	{
		
	}
	
	public function show() : Void
	{
		dom.css("display", "block");
		dom.css("z-index", "1");
	}
	
	public function play() : Void
	{
		resize(BoundProvider.winW, BoundProvider.winH);
	}
	
	
	
	public function hide() : Void
	{
		
	}
	
	public function removeChild() : Void
	{
		dom.css("display", "none");
		dom.css("z-index", "1");
	}
	
	public function resize( _w : Int , _h : Int ) : Void
	{
		container.css("width", _w + "px");
		container.css("height", _h + "px");
		
		setHeight(_h);
		setWidth(_w);
		
		dom.css("background-position", BoundProvider.bgX+"px "+BoundProvider.bgY+"px");
		dom.css("background-size", BoundProvider.bgW+"px "+BoundProvider.bgH+"px");
	}
	
}